//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include <ddk.h>
#include "..\serial\sercommdev.h"

#define BLUETOOTH_POWERON       1
#define BLUETOOTH_POWEROFF      2


class BlueTooth : public CDeviceDriver
{
public:
    CARAPI Read(
                    /* [in] */ Int64 u64Offset,
                    /* [in] */ Int32 bytesToRead,
                    /* [out] */ MemoryBuf * pBuffer,
                    /* [out] */ IEvent * * ppCompletionEvent);
    CARAPI Write(
                    /* [in] */ Int64 u64Offset,
                    /* [in] */ const MemoryBuf &buffer,
                    /* [out] */ Int32 * pBytesWritten,
                    /* [out] */ IEvent * * ppCompletionEvent);
    CARAPI Control(
                    /* [in] */ Handle32 nControlCode,
                    /* [in] */ const MemoryBuf &inBuffer,
                    /* [out] */ MemoryBuf * pOutBuffer,
                    /* [out] */ IEvent * * ppCompletionEvent);
    virtual void  Dispose();
};

ECode BlueTooth::Read(
                /* [in] */ Int64 u64Offset,
                /* [in] */ Int32 bytesToRead,
                /* [out] */ MemoryBuf *pBuffer,
                /* [out] */ IEvent * * ppCompletionEvent)
{
    return E_NOT_IMPLEMENTED;
}

ECode BlueTooth::Write(
                /* [in] */ Int64 u64Offset,
                /* [in] */ const MemoryBuf &buffer,
                /* [out] */ Int32 * pBytesWritten,
                /* [out] */ IEvent * * ppCompletionEvent)
{
    return E_NOT_IMPLEMENTED;
}

ECode BlueTooth::Control(
                /* [in] */ Handle32 nControlCode,
                /* [in] */ const MemoryBuf &inBuffer,
                /* [out] */ MemoryBuf * pOutBuffer,
                /* [out] */ IEvent * * ppCompletionEvent)
{
    if (nControlCode == BLUETOOTH_POWERON) {
        bluetooth_power_on();
    }
    if (nControlCode == BLUETOOTH_POWEROFF) {
        bluetooth_power_off();
    }
    return NOERROR;
}

void BlueTooth::Dispose()
{
    delete this;
}

EXTERN IDeviceDriver * CDECL BlueToothPowerOn(uint_t uDeviceNo, void *pvParameter)
{
    BlueTooth *pBlue = new BlueTooth();
    if (NULL == pBlue) return NULL;

    bluetooth_power_on();
    cprintf("bluetooth power on\n");
    return pBlue;
}
